package com.hhss.qishi.DPtest.designpattern.command;

import java.util.Stack;

/**
 * 遥控器
 */
public class RemoteController {

    private Command command = new DefaultCommand();

    private Stack<Command> executedCommandStack = new Stack();

    public void setCommand(Command command){
        this.command = command;
    }

    /**
     * 按下按钮
     */
    public void pressButton(){
        command.execute();
        executedCommandStack.push(command);
    }

    /**
     * 回滚
     */
    public void rollBackCommand(){
        if(!executedCommandStack.isEmpty()){
            executedCommandStack.pop().execute();
        }
    }
}
